<template>
  <div class="goods-hot">
    <h3>{{title}}</h3>
    <div v-if="goodsList">
      <GoodsItem v-for="item in goodsList" :key="item.id" :goods="item"></GoodsItem>
    </div>
  </div>
</template>

<script>
import { computed, ref } from '@vue/runtime-core'
import GoodsItem from '../../category/components/goods-item.vue'
import { findGoodsHot } from '@/api/product'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  components: { GoodsItem },
  props: {
    // 热榜类型
    type: {
      type: Number,
      default: 1
    }
  },
  setup (props) {
    // 类型数据字典
    const types = { 1: '24小时热销榜', 2: '总热销榜', 3: '周热销榜' }
    // 使用计算属性得到标题
    const title = computed(() => {
      return types[props.type]
    })
    // 发送请求拿到商品数据
    const goodsList = ref([])
    // 拿到商品id
    const route = useRoute()
    findGoodsHot({ id: route.params.id, type: props.type }).then(data => {
      goodsList.value = data.result
      // console.log(data.result)
    })
    // console.log(goodsList.value)
    return { title, goodsList }
  }
}
</script>

<style lang="less" scoped>
.goods-hot{
  h3{
    height: 70px;
    background: @helpColor;
    color:#fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    font-weight: normal;
  }
}
:deep(.goods-item){
  background:#fff;
  width: 99.84%;
  margin-bottom: 10px;
  img{
    width: 200px;
    height: 200px;
  }
  p{
    margin: 0 10px;
  }
  &:hover{
    transform:none;
    box-shadow: none;
  }
}
</style>
